package cz.uvn.orthopedy.server.jdo;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import cz.uvn.orthopedy.client.LoginInfo;

public final class LoginJdo {
	
	private LoginJdo() {
	}

	public static LoginInfo login(String requestUri) {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		LoginInfo loginInfo = new LoginInfo();

		if (user != null) {
			loginInfo.setLoggedIn(true);
			loginInfo.setEmailAddress(user.getEmail());
			loginInfo.setNickname(user.getNickname());
			loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
		} else {
			loginInfo.setLoggedIn(false);
			loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
		}
		return loginInfo;
	}

//	public static Hall getHall(Long id) {
//		PersistenceManager pm = PMF.get().getPersistenceManager();
//		try {
//			Query query = pm.newQuery(Hall.class);
//			query.setFilter("id == idParam");
//			query.declareParameters("Long idParam");
//			query.setUnique(true);
//			return (Hall) query.execute(id);
//		} finally {
//			pm.close();
//		}
//	}

}
